package keqiang.com.kq_flutter_core_widget.channel;

import android.app.Activity;
import android.content.Context;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import keqiang.com.kq_flutter_core_widget.interf.INotice;
import me.zhouzhuo810.magpiex.ui.act.BaseActivity;

/**
 * flutter 通知发送通道
 *
 * @author zhouzhuo810
 * @date 2023/8/4 14:10
 */
public class NativeNoticeChannel extends MethodChannel {
    
    // 通道id
    private static final String CHANNEL = "flutter.keqiang.com/notice";
    
    private static final String METHOD_SHOW_NOTICE_FOR_API_TEST = "showNoticeForApiTest";
    
    private Context mContext;
    
    public NativeNoticeChannel(@NonNull BinaryMessenger messenger) {
        super(messenger, CHANNEL);
        
        init();
    }
    
    
    public void setContext(Context context) {
        mContext = context;
    }
    
    private void init() {
        setMethodCallHandler(new MethodCallHandler() {
            @Override
            public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
                switch (call.method) {
                    case METHOD_SHOW_NOTICE_FOR_API_TEST:
                        if (mContext != null) {
                            if (mContext instanceof INotice) {
                                String title = call.argument("title");
                                String showContent = call.argument("showContent");
                                String copyContent = call.argument("copyContent");
                                ((INotice) mContext).showNoticeForApiTest(title, showContent, copyContent);
                            }
                        }
                        break;
                }
                result.success(true);
            }
        });
    }
}
